const express = require("express");
const multer = require("multer");

// 创建app对象
const app = express();

const formdata = multer();

// 编写中间件
// 1.解析queryString
app.get("/home/list", (req, res, next) => {
  const queryInfo = req.query;
  console.log(queryInfo);

  res.end("data list middleware");
});

// 2.解析params参数
app.get("/users/:id", (req, res, next) => {
  const id = req.params.id;
  res.end("params middleware" + id);
});

// 3.解析json
app.post("/users", express.json(), (req, res, next) => {
  const body = req.body;
  console.log(body);

  res.end("json middleware");
});

// 启动服务器
app.listen(9000, () => {
  console.log("express服务器启动成功~");
});
